//-----------------------------------------------------------------------------
// File: HorizontalStraightShape.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace ObjectiveDraw.Platform
{
	/// <summary>
	/// Summary description for HorizontalStrightShape.
	/// </summary>
	public class HorizontalStraightShape : SinglePointShapeBase 
	{
		#region IDrawerShape Members

		
		public override float DistanceFrom(ObjectiveDraw.Platform.DrawerChartBase control, System.Drawing.PointF point)
		{
			float yo1 = OffsetFromOrdinate(control, PointOrdinate);

			double dy1 = point.Y - yo1;

			return (float)Math.Abs(dy1);
		}

		public override void RenderShape(DrawerChartBase control, ChartInfoArgs cinfo, Cerebrum.Direct3D.Forms.RenderEventArgs re, float z)
		{
			base.RenderShape (control, cinfo, re, z);

			Microsoft.DirectX.Direct3D.Device device = re.Device;

			float y1 = OffsetFromOrdinate(control, PointOrdinate);

			System.Drawing.RectangleF _view = re.ClipRectangle;

			float x1 = _view.X;
			float x2 = _view.X + _view.Width;

			VertexBuffer VertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 2, device, Usage.WriteOnly, CustomVertex.TransformedColored.Format, Pool.SystemMemory);

			device.VertexFormat = CustomVertex.TransformedColored.Format;

			// set the vertexbuffer stream source
			device.SetStreamSource(0, VertexBuffer, 0, VertexInformation.GetFormatSize(CustomVertex.TransformedColored.Format));
			// set fill mode
			device.RenderState.FillMode = FillMode.Solid;

			int clr = this.m_ForeColor.ToArgb();

			CustomVertex.TransformedColored[] verts = (CustomVertex.TransformedColored[])VertexBuffer.Lock(0,0); // Lock the buffer (which will return our structs)

			verts[0].Position = new Vector4(x1, y1, z, 1.0f);
			verts[0].Color = clr;

			verts[1].Position = new Vector4(x2, y1, z, 1.0f);
			verts[1].Color = clr;

			VertexBuffer.Unlock();


			//use the indices buffer
			device.DrawPrimitives(PrimitiveType.LineList, 0, 1);

			VertexBuffer.Dispose();

		}

		#endregion
	}
}
